package tinybase.sm;

import java.util.Scanner;

import javax.rmi.PortableRemoteObject;

import tinybase.pf.PF_Manager;
import tinybase.rm.RM_Manager;

public class Console implements Runnable{
	
	Scanner s= new Scanner(System.in);
	public static final String PROMPT= "TINYBASE >> ";
	public String[] command;
	public RQLParser rqlParser;
	private PF_Manager pfm;
	private RM_Manager rmm;
	
	public Console() {
		this.command= new String[4];
		this.rqlParser= new RQLParser(System.in);
		new Thread(this).start();
	}
	
	public void parse(String[] command) {
//System.out.print(command[0]);
		System.out.println();
		if (command[0].equals("dbcreate"))
			new DBCreate(pfm, rmm).createDB(command);
	}
	
	public void setInput(String input) {
		command= input.split(" ");
		command[0].trim();
		this.parse(command);
	}
	
	/*
	 * help informations
	 */
	public void showList() {
	}

	void showPath(String str) {
		System.out.print(str + PROMPT);
	}
	
	public static void main(String[] args) {
		new Console();
	}
	
	@Override
	public void run() {
		String str= null;
//		showPath(SM_Internal.DEFAULTPATH);
		System.out.print(PROMPT);
		
		while (true) {
			str= s.nextLine();
			if (str != null) {
				System.out.print(PROMPT + str);
//				try {
//					rqlParser.command();
//				} catch (ParseException e) {
//					e.printStackTrace();
//				}
				if (!str.equals("")) {
					command= str.split(" ");
					this.parse(command);
				} else {
					System.out.print(PROMPT);
				}
			}
		}
	}
	
}
